package org.moonlight.jvm.instructions.comparisons.lcmp;

import org.moonlight.jvm.instructions.base.NoOperandsInstruction;
import org.moonlight.jvm.rtda.exclusive.Frame;
import org.moonlight.jvm.rtda.exclusive.OperandStack;

/**
 * LCMP: lcmp指令用于比较long变量。
 *
 * @author Moonlight
 * @createTime 2023/8/22 17:22
 **/
public class LCmp extends NoOperandsInstruction {

    @Override
    public void execute(Frame frame) {
        OperandStack stack = frame.getOperandStack();
        long a = stack.popLong();
        long b = stack.popLong();

        if (a > b) {
            stack.pushInt(-1);
        } else if (a == b) {
            stack.pushInt(0);
        } else {
            stack.pushInt(1);
        }
    }
}
